package cn.wolfcode.web.interceptor;



import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UtilContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class CheckLoginInterceptor implements HandlerInterceptor {


    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        //从session中获取到用户信息
        //Object employee = request.getSession().getAttribute("USER_IN_SESSION");
        Employee employee = UtilContext.getCurrentUser();


        //如果获取到的不为空
        if (employee != null) {
            return true;//放行
        }
        //否则回到登录界面
        response.sendRedirect("/login.html");

        return false;
    }
}
